package com.affectu.message;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.validator.Length;
import org.jboss.seam.annotations.Name;

import com.affectu.common.base.EntityBase;
import com.affectu.user.User;

/*
 * 2008-8-26
 * @author daniel nathan
 */
@Entity
@Name("message")
public class Message extends EntityBase {

	private static final long serialVersionUID = -5824523776136246361L;

	private String topic;

	@Length(max = 1024)
	private String content;

	@Temporal(value = TemporalType.TIMESTAMP)
	private Date sendDate;

	private Status status;

	public enum Status {
		NEW, READED, TRASH
	};

	@ManyToOne(cascade = CascadeType.REFRESH)
	@JoinColumn(name = "senderId", referencedColumnName = "id")
	private User sender;

	@ManyToOne(cascade = CascadeType.REFRESH)
	@JoinColumn(name = "receiverId", referencedColumnName = "id")
	private User receiver;

	@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinTable(name = "Messages_receivers", joinColumns = { @JoinColumn(name = "messageId", referencedColumnName = "id") }, inverseJoinColumns = { @JoinColumn(name = "receiverIds", referencedColumnName = "id") })
	private List<User> receivers;

	public String getTopic() {
		return topic;
	}

	public void setTopic(String topic) {
		this.topic = topic;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}

	public User getSender() {
		return sender;
	}

	public void setSender(User sender) {
		this.sender = sender;
	}

	public List<User> getReceivers() {
		return receivers;
	}

	public void setReceivers(List<User> receivers) {
		this.receivers = receivers;
	}

	public Date getSendDate() {
		return sendDate;
	}

	public void setSendDate(Date sendDate) {
		this.sendDate = sendDate;
	}

	public User getReceiver() {
		return receiver;
	}

	public void setReceiver(User receiver) {
		this.receiver = receiver;
	}
}
